﻿using System.Data;
using System.Data.SqlClient;
namespace MyWeb.Data
{
	public class tblUSER_PROFILEDAL : SqlDataProvider
	{

		#region[tblUSER_PROFILE_GetbyAll]
		public DataTable tblUSER_PROFILE_GetByAll()
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_GetByAll", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				return GetTable(cmd);
			}
		}
		#endregion
		#region[tblUSER_PROFILE_GetbyId]
		public DataTable tblUSER_PROFILE_GetById(string USERID)
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_GetById", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@USERID", USERID));return GetTable(cmd);
			}
		}
		#endregion
		#region[tblUSER_PROFILE_GetbyTop]
		public DataTable tblUSER_PROFILE_GetByTop(string Top, string Where, string Order)
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_GetByTop", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				cmd.Parameters.Add(new SqlParameter("@Top",Top));
				cmd.Parameters.Add(new SqlParameter("@Where",Where));
				cmd.Parameters.Add(new SqlParameter("@Order",Order));
				return GetTable(cmd);
			}
		}
		#endregion
		#region[tblUSER_PROFILE_Insert]
		public void tblUSER_PROFILE_Insert(tblUSER_PROFILEInfo Data)
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_Insert", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@USERID", Data.USERID));
				cmd.Parameters.Add(new SqlParameter("@USERNAME", Data.USERNAME));
				cmd.Parameters.Add(new SqlParameter("@PASSWORD", Data.PASSWORD));
				cmd.Parameters.Add(new SqlParameter("@EMAIL", Data.EMAIL));
				cmd.Parameters.Add(new SqlParameter("@LASTLOGIN_DATE", Data.LASTLOGIN_DATE));
				cmd.Parameters.Add(new SqlParameter("@CREATE_USER", Data.CREATE_USER));
				cmd.Parameters.Add(new SqlParameter("@CREATE_DATE", Data.CREATE_DATE));
				cmd.Parameters.Add(new SqlParameter("@USER_EDIT", Data.USER_EDIT));
				cmd.Parameters.Add(new SqlParameter("@DATE_EDIT", Data.DATE_EDIT));
				cmd.Parameters.Add(new SqlParameter("@STATUS", Data.STATUS));
				ExeCuteNonquery(cmd);
			}
		}
		#endregion
		#region[tblUSER_PROFILE_Update]
		public void tblUSER_PROFILE_Update(tblUSER_PROFILEInfo Data)
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_Update", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@USERID", Data.USERID));
				cmd.Parameters.Add(new SqlParameter("@USERNAME", Data.USERNAME));
				cmd.Parameters.Add(new SqlParameter("@PASSWORD", Data.PASSWORD));
				cmd.Parameters.Add(new SqlParameter("@EMAIL", Data.EMAIL));
				cmd.Parameters.Add(new SqlParameter("@LASTLOGIN_DATE", Data.LASTLOGIN_DATE));
				cmd.Parameters.Add(new SqlParameter("@CREATE_USER", Data.CREATE_USER));
				cmd.Parameters.Add(new SqlParameter("@CREATE_DATE", Data.CREATE_DATE));
				cmd.Parameters.Add(new SqlParameter("@USER_EDIT", Data.USER_EDIT));
				cmd.Parameters.Add(new SqlParameter("@DATE_EDIT", Data.DATE_EDIT));
				cmd.Parameters.Add(new SqlParameter("@STATUS", Data.STATUS));
				ExeCuteNonquery(cmd);
			}
		}
		#endregion
		#region[tblUSER_PROFILE_Delete]
		public void tblUSER_PROFILE_Delete(string USERID)
		{
			using (var cmd = new SqlCommand("sp_tblUSER_PROFILE_Delete", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@USERID",USERID));
				ExeCuteNonquery(cmd);
			}
		}
		#endregion
        #region[sptblUSER_PROFILE_CheckLogin]
        public int sptblUSER_PROFILE_CheckLogin(string Username, string Password)
        {
            using (var cmd = new SqlCommand("sptblUSER_PROFILE_CheckLogin", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                var da = new SqlDataAdapter(cmd);
                cmd.Parameters.Add(new SqlParameter("@UserName", Username));
                cmd.Parameters.Add(new SqlParameter("@PassWord", Password));
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count >= 1)
                {
                    return int.Parse(dt.Rows[0]["Status"].ToString());

                }
                else
                {
                    return -1;
                }

            }
        }
        #endregion
	}
}